using System;
using SoftwareMonkeys.Scriptech.Stores;
using System.IO;

namespace SoftwareMonkeys.Scriptech.Projects
{
	public class ProjectAssemblyFileNamer
	{
		public static string CreateAssembliesDirectoryPath(string storeName, string groupName, string projectName, string assembliesDirectory)
		{		
			Store store = StoreReader.GetStore(storeName);
			
			if (store == null)
				throw new ArgumentException("Cannot find store with name '" + storeName + "'.");
			
			if (assembliesDirectory == null)
				assembliesDirectory = string.Empty;
			
			return store.RootPath + Path.DirectorySeparatorChar
				+ groupName + Path.DirectorySeparatorChar
				+ projectName + Path.DirectorySeparatorChar
				+ assembliesDirectory.TrimStart('/');		
		}
		
		public static string CreateAssemblyPropertiesPath(string storeName, string groupName, string projectName, string assemblyDirectory, string assemblyName)
		{
			return CreateAssemblyPath(storeName, groupName, projectName, assemblyDirectory, assemblyName) + Path.DirectorySeparatorChar + assemblyName + ".assembly";
		}
		
		public static string CreateAssemblyPropertiesPath(string storeName, string groupName, string projectName, string assemblyName)
		{
			return CreateAssemblyPath(storeName, groupName, projectName, assemblyName) + Path.DirectorySeparatorChar + assemblyName + ".assembly";
		}
		
		public static string CreateAssemblyPropertiesPath(string storeName, string groupName, string projectName, ProjectAssembly assembly)
		{
			return CreateAssemblyPath(storeName, groupName, projectName, assembly) + Path.DirectorySeparatorChar + assembly.Name + ".assembly";
		}
		
		public static string CreateAssemblyPath(string storeName, string groupName, string projectName, string assemblyName)
		{
			ProjectAssembly assembly = ProjectAssemblyReader.GetAssembly(storeName, groupName, projectName, assemblyName);
			
			if (assembly == null)
				throw new ArgumentException("Can't find assembly '" + assemblyName + "'.");
				
			return CreateAssemblyPath(storeName, groupName, projectName, assembly);
		}
		
		public static string CreateAssemblyPath(string storeName, string groupName, string projectName, ProjectAssembly assembly)
		{
			if (assembly.Directory == null || assembly.Directory == String.Empty)
				throw new ArgumentException("An assembly directory must be specified.", "assembly.Directory");
			
			Project project = ProjectReader.GetProject(storeName, groupName, projectName);
			
			if (project == null)
				throw new ArgumentException("Can't find project '" + projectName + "'.");
			
			string path = ProjectFileNamer.GetProjectPath(storeName, groupName, projectName)
				+ Path.DirectorySeparatorChar + project.AssembliesDirectory
				+ Path.DirectorySeparatorChar + assembly.Directory;

			return path;
		}
		
		public static string CreateAssemblyPath(string storeName, string groupName, string projectName, string assemblyDirectory, string assemblyName)
		{
			if (assemblyDirectory == null || assemblyDirectory == String.Empty)
				throw new ArgumentException("An assembly directory must be specified.", "assemblyDirectory");
			
			Project project = ProjectReader.GetProject(storeName, groupName, projectName);
			
			if (project == null)
				throw new ArgumentException("Can't find project '" + projectName + "'.");
			
			string path = ProjectFileNamer.GetProjectPath(storeName, groupName, projectName)
				+ Path.DirectorySeparatorChar + project.AssembliesDirectory
				+ Path.DirectorySeparatorChar + assemblyDirectory;

			return path;
		}
	}
}

